package com.dehui.traders.ui.msg;

import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.MsgBean;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.ui.market.rank.RankItemAdapter;
import com.dehui.traders.ui.market.rankdetail.RankDetailActivity;
import com.dehui.traders.ui.stockdetail.StocksDetailActivity;
import com.dehui.traders.ui.web.WebDetailActivity;
import com.dehui.traders.utils.BaseRecyclerAdapter;
import com.dehui.traders.utils.SmartViewHolder;

import java.util.Collection;
import java.util.List;

public class MsgListAdapter extends BaseRecyclerAdapter<MsgBean> {

    private final Activity context;

    public MsgListAdapter(Collection<MsgBean> collection, Activity context) {
        super(collection, R.layout.list_item_msg);
        this.context = context;
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, MsgBean model, int position) {
        TextView tvTitle = holder.findViewById(R.id.tv_title);
        TextView tvcontent = holder.findViewById(R.id.tv_content);
        TextView tvTime = holder.findViewById(R.id.tv_time);

        tvTitle.setText(model.getName());
        tvcontent.setText(model.getContent());
        tvTime.setText(model.getTime());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("1".equals(model.getFlag())){
                    StocksDetailActivity.start(context,"消息",model.getName(),model.getCode(),model.getClosePrice(),model.getMarket());
                } else if ("2".equals(model.getFlag())){
                    WebDetailActivity.start(context,model.getName(),model.getUrl());
                }
            }
        });

    }
}
